#region License
/*

	Copyright (C) 2008 Oliver Charles, Daniel Hollander

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
	
*/
#endregion

using System;

namespace Moebius.Core
{
    /// <summary>
    /// Represents a stopwatch, that is accurate down to nanoseconds.
    /// </summary>
    public class Stopwatch
    {
      //private readonly long frequency;
      //  private long lastTime;

        private DateTime lastTime;

        /// <summary>
        /// Creates a new Stopwatch, and starts it.
        /// </summary>
        public Stopwatch()
        {
	  // Todo - removed for Unix
	  //if (!NativeMethods.QueryPerformanceFrequency(ref frequency))
	  //    throw new InvalidOperationException("Hardware does not support high frequency counters");
            Reset();
        }

        /// <summary>
        /// Resets the stopwatch, and starts it again.
        /// </summary>
        public void Reset()
        {
            lastTime = DateTime.Now;
	  // if(!NativeMethods.QueryPerformanceCounter(ref lastTime))
	  //    throw new InvalidOperationException("Hardware does not support high frequnecy counters");
        }

        /// <summary>
        /// Returns the time since lap was last called.
        /// </summary>
        /// <returns>A double containing the time since Lap was last called, in seconds.</returns>
        public double Lap()
        {
	  //long currTime = 0;
	  //NativeMethods.QueryPerformanceCounter(ref currTime);

	  //double elapsed = (currTime - lastTime) / (double)frequency;
	  //lastTime = currTime;
	    DateTime currTime = DateTime.Now;
	    TimeSpan elapsed = currTime - lastTime;
	    lastTime = currTime;

            return elapsed.TotalSeconds;
        }
    }
}